﻿using System.Collections.Generic;
using UnityEngine;

public class FPSCounter: MonoBehaviour
{    
    public float updateInterval = 0.5f;    
    private float lastTime;
    int frames = 0;        
    string fpsString = "60";

    private void Awake()
    {
        UnGfx.SetResolution(720, true);
    }

    void Start()
    {        
        lastTime = Time.time;
        frames = 0;
    }

    void Update()
    { 
        ++frames;
        float timeNow = Time.time;        

        if (timeNow > lastTime + updateInterval)
        {
            int fps = (int)(frames / (timeNow - lastTime));
            frames = 0;
            lastTime = timeNow;
            fpsString = fps.ToString();                         
        }
    }

    void OnGUI()
    {
        GUI.Label(new Rect(Screen.width - 50, 20, 60, 20), fpsString);
    }
}